package cn.darkfire.web.Controller;

import cn.darkfire.web.POJO.LoginUser;
import cn.darkfire.web.Service.UserService;
import cn.darkfire.web.Service.impl.UserServiceImpl;
import cn.darkfire.web.Utils.PageUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getUserByPage.do")
public class GetUserPageController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String page = req.getParameter("page");
        String num = req.getParameter("num");
        int p = 1, n=10;
        try{
             p = Integer.valueOf(page);
             n = Integer.valueOf(num);
        }catch (Exception e){
             p = 1;n=10;
        }
        UserService userService = new UserServiceImpl();
        List<LoginUser> list = PageUtils.getInstance().splitList(userService.getAllUser(),p,n);
        req.getSession().setAttribute("users",list);
        req.getSession().setAttribute("bar",PageUtils.getInstance().getSb(userService.getAllUser(), p,n));
        resp.sendRedirect("user.jsp");
    }
}
